For these kind of problems, tech is not really a solution. So better talk to a registered psychologist or psychiatrist.
But on the tech side, for android users, 'Open TimeLimit' is a useful app. It's like an advanced app locker, with timers and stuff. It's FOSS and on Fdroid:
Edit: Make sure to disable the app when you go out etc. Because it might cause obstacles during emergencies. Depends on the way you set it up of course.