Skip to content

Commit

Permalink
Revert "Revert "Merge branch 'master' of https://github.com/NexInfini…
Browse files Browse the repository at this point in the history
…te/hivenpy""

This reverts commit 07427a9.
  • Loading branch information
NexInfinite committed Aug 7, 2020
1 parent 2d01154 commit 5d385b1
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 14 deletions.
18 changes: 18 additions & 0 deletions Examples/Basic/roll.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from random import randint

from Hiven.client import Bot, events

TOKEN = "[Your token]"
bot = Bot(TOKEN)

@events.event
def on_ready():
print(f"Using {bot.user.name}")

@events.event
def on_message(ctx):
if ctx.author.id != bot.user.id:
if ctx.message == "!roll":
ctx.send(randint(1, 6))

bot.login()
8 changes: 8 additions & 0 deletions Hiven/Objects/member_exit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class member_exit_obj:
def __init__(self, ctx):
self.user = self.User(ctx)
self.house_id = ctx['house_id']

class User:
def __init__(self, ctx):
self.id = ctx['id']
8 changes: 7 additions & 1 deletion Hiven/Objects/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ def __init__(self, ctx):
self.timestamp = ctx['timestamp']
self.id = ctx['id']
self.mentions = ctx['mentions']
# edit mentions

class Author:
def __init__(self, ctx):
author_json = ctx['author']

self.username = author_json['username']
self.name = author_json['name']
self.id = author_json['id']
self.icon = author_json['icon']

def getIconURL(self):
return f"https://media.hiven.io/v1/users/{self.id}/icons/{self.icon}"

def send(self, message):
self.bot.send(message=message, room_id=self.room_id)
self.bot.send(message=message, room_id=self.room_id)
21 changes: 21 additions & 0 deletions Hiven/Objects/message_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class message_update_obj:
def __init__(self, ctx):
self.message = self.Message(ctx)
self.author = self.Author(ctx)
self.room_id = ctx['room_id']
self.house_id = ctx['house_id']

class Message:
def __init__(self, ctx):
self.content = ctx['content']
self.timestamp = ctx['timestamp']
self.id = ctx['id']
self.mentions = ctx['mentions']

class Author:
def __init__(self, ctx):
author_json = ctx['author']
self.username = author_json['username']
self.name = author_json['name']
self.id = author_json['id']
self.iconURL = f"https://media.hiven.io/v1/users/{author_json['id']}/icons/{author_json['icon']}"
28 changes: 17 additions & 11 deletions Hiven/Websocket/websocket_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import time

from Hiven.Objects.bot_user import *
from Hiven.Objects.message import *
from Hiven.Objects.house import *
from Hiven.Objects.member_enter import *
from Hiven.Objects.member_exit import *
from Hiven.Objects.message import *
from Hiven.Objects.message_update import *
from Hiven.Objects.typing import *

from Hiven.Events.events import *


Expand Down Expand Up @@ -44,25 +47,28 @@ def on_message(self, ws, context):
if context_json["op"] == 1:
self.HEARTBEAT = context_json["d"]["hbt_int"]
else:
ctx_json = context_json['d']
event = context_json['e']
if self.OUTPUT:
print(context_json)
if context_json['e'] == "MESSAGE_CREATE":
ctx_json = context_json['d']
if event == "MESSAGE_CREATE":
ctx = ctx_obj(ctx_json, self.outer)
events.call(ctx, "on_message")
elif context_json['e'] == "TYPING_START":
ctx_json = context_json['d']
elif event == "TYPING_START":
ctx = typing_ctx_obj(ctx_json)
events.call(ctx, "on_typing")
elif context_json['e'] == "HOUSE_JOIN":
ctx_json = context_json['d']
elif event == "HOUSE_JOIN":
ctx = house_ctx_obj(ctx_json)
events.call(ctx, "on_house_join")
elif context_json['e'] == "HOUSE_MEMBER_ENTER":
ctx_json = context_json['d']
elif event == "HOUSE_MEMBER_ENTER":
ctx = member_enter_obj(ctx_json)
events.call(ctx, "on_member_enter")
elif context_json['e'] == "INIT_STATE":
ctx_json = context_json['d']
elif event == "INIT_STATE":
self.outer.user = bot_user(ctx_json)
events.call(None, "on_ready")
elif event == "HOUSE_MEMBER_EXIT":
ctx = member_exit_obj(ctx_json)
events.call(ctx, "on_member_exit")
elif event == "MESSAGE_UPDATE":
ctx = message_update_obj(ctx_json)
events.call(ctx, "on_message_update")
Binary file removed Images/AUTH.jpg
Binary file not shown.
Binary file added Images/Local Storage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Images/TOKEN.png
Binary file not shown.
Binary file removed Images/authimage.png
Binary file not shown.
Binary file added Images/console.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Images/messagesimages.PNG
Binary file not shown.
Binary file removed Images/networktab.PNG
Binary file not shown.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pip install hivenpy
```

### Getting your token
Make a bot account for your hiven bot then open up chrome dev tools (F12) and go to the console tab.
Make a bot account for your hiven bot. Open up the console by pressing Command+Option+J (Mac) Control+Shift+J (Windows, Linux, Chrome OS).
<br><br>
![Image not found](https://github.com/NexInfinite/hivenpy/blob/master/Images/console.png?raw=true)
<br>Type `localStorage['hiven-auth']` and hit enter.
Expand Down Expand Up @@ -50,7 +50,7 @@ You can see a list of all examples in the folder names [Examples](Examples).

# Please note
~~At the moment we don't have a pip package set up as it's not at that stage yet but you can still make
self bots with this.~~ We now have a [pip package](https://pypi.org/project/hivenpy/1.6/)! Download it to try everything out.
self bots with this.~~ We now have a [pip package](https://pypi.org/project/hivenpy/)! Download it to try everything out.
This is a work in progress project so everything is going to change soon. This is temporary so you can start making
and experimenting with new bots now.
<br><br>
Expand Down

0 comments on commit 5d385b1

Please sign in to comment.