コード例 #1
0
    async def pointbalance(self, ctx):
        """Returns balance and transaction history of feli points."""

        secret = get_secret(self._secret_name)
        query = """select * from feli_point_balance"""
        results = run_query(secret['host'],
                            secret['username'],
                            secret['password'],
                            secret['dbInstanceIdentifier'],
                            query,
                            returns_results=True,
                            return_column_names=True)

        table = PrettyTable()

        table.field_names = results[0]

        for row in results[1:]:
            table.add_row(row)

        df = pd.DataFrame(results[1:], columns=results[0])
        df = df.set_index('custom_nickname')
        for i in range(len(df)):
            plt.plot([k for k in df.columns if k != 'total_balance'], [
                int(df[y].iloc[i]) for y in df.columns if y != 'total_balance'
            ])
        plt.legend(df.index, loc="upper left")
        output_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                   'balance.png')
        plt.savefig(output_file)

        await ctx.send('```{}```'.format(table),
                       file=discord.File(output_file))
コード例 #2
0
    async def felipoint(self, ctx, amount, recipient, type):
        """<amount> <recipient> <type>: Adds or removes a feli points to a user."""

        help_text = 'Usage is ```!felipoint <amount> <recipient> <type>```'

        if type not in ['add', 'remove']:
            await ctx.send('Invalid transaction type!')
            await ctx.send(help_text)
            return None

        if not is_valid_user(recipient):
            await ctx.send('Invalid point recipient!')
            await ctx.send(help_text)
            return None

        try:
            int(amount)
        except ValueError:
            await ctx.send('Amount must be an integer number!')
            await ctx.send(help_text)
            return None

        secret = get_secret(self._secret_name)

        if type == 'add' and recipient != 'feli':
            query = """insert into feli_point_transactions (discord_user_id, type, amount, given_by)
                               values ('{}', '{}', '{}', '{}')
                               """.format(ctx.message.author, 'remove', amount,
                                          ctx.message.author)
            run_query(secret['host'],
                      secret['username'],
                      secret['password'],
                      secret['dbInstanceIdentifier'],
                      query,
                      auto_commit=True)

        query = """insert into feli_point_transactions (discord_user_id, type, amount, given_by)
                   select discord_user_id, '{}', '{}', '{}'
                   from users
                   where custom_nickname = '{}'""".format(
            type, amount, ctx.message.author, recipient)
        run_query(secret['host'],
                  secret['username'],
                  secret['password'],
                  secret['dbInstanceIdentifier'],
                  query,
                  auto_commit=True)

        await ctx.send('Transaction completed :eggplant:')

        return None
コード例 #3
0
ファイル: is_valid_user.py プロジェクト: ksco92/SimpBot
def is_valid_user(user_nickname):
    """Checks if the nickname of a user is valid."""

    secret_name = 'simp/rds'
    secret = get_secret(secret_name)
    query = """select custom_nickname
               from users
               where custom_nickname = '{}'""".format(user_nickname)
    results = run_query(secret['host'],
                        secret['username'],
                        secret['password'],
                        secret['dbInstanceIdentifier'],
                        query,
                        returns_results=True)

    if len(results) == 1:
        return True
    else:
        return False
コード例 #4
0
ファイル: simp_bot.py プロジェクト: ksco92/SimpBot
from commands.feli_points.feli_points import FeliPoints
from commands.generic.taylor import Taylor
from utils.get_secret import get_secret

secret_name = 'simp/rds'
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix='!', intents=intents)

bot.add_cog(FeliPoints(bot))
bot.add_cog(Taylor(bot))


@bot.command()
async def culo(ctx):
    """Returns time in which rick hasn't licked Ximena's ass."""

    today = datetime.datetime.now()
    start_date = datetime.datetime(2020, 10, 10)
    diff = today - start_date
    days, seconds = diff.days, diff.seconds
    hours = seconds // 3600
    minutes = (seconds % 3600) // 60
    seconds = seconds % 60
    await ctx.send(
        'Rick no le ha chupado el culo a Ximena  en {} dias, {} horas, {} minutos y {} segundos'
        .format(days, hours, minutes, seconds))


bot.run(get_secret('simp/bot-token')['token'])
コード例 #5
0
from utils.get_secret import get_secret
from pymongo import MongoClient
import os
notified_people= os.getenv("NOTIF_EMAILS").split(',')
mongo_user = get_secret('mongo-user')
mongo_pass = get_secret('mongo-pass')
client = MongoClient('tina_dev_tina-mongo', 27017,username=mongo_user, password=mongo_pass)
from utils.emails import send_email
import json
from utils.dateconverter import dateConverter
class ticketsManager(object):
    openedTickets=[]
    pastNotifs=[]
    def __init__(self) :
        q= client.zabbix.tickets.find({})
        for ticket in q:    
            self.openedTickets.append(ticket['eventid'])
        q= client.zabbix.notifications.find({})
        for notif in q:    
            self.pastNotifs.append(notif['eventid'])
        
        

    def OpenTicket(self, prediction):

        
        subject = f"ALFRED: TICKET WOULD HAVE BEEN CREATED : {prediction['host_short_name']} in {prediction['host_environment']}"
        body = f"{prediction['description']} \n"
        body = f"{body} {json.dumps(prediction,default=dateConverter)}"
        send_email(subject,body,  notified_people)
        self.openedTickets.append(prediction['eventid'])
コード例 #6
0
from ai.catboost import CatBoostModel
#from utils.dataset import updateModelDataFromAPIResults
import logging
from utils.get_secret import get_secret
import os
from pymongo import MongoClient
#getting configuration information
MODE = os.getenv("MODE")

from utils.emails import send_email

notified_people = os.getenv("NOTIF_EMAILS").split(',')
#notified_people= ['*****@*****.**']

ZABBIX_URL = os.getenv("ZABBIX_URL")
mongo_user = get_secret('mongo-user')
mongo_pass = get_secret('mongo-pass')
zabbix_user = get_secret("zabbix-user")
zabbix_pass = get_secret("zabbix-pass")
client = MongoClient('tina_dev_tina-mongo',
                     27017,
                     username=mongo_user,
                     password=mongo_pass)
# Settings for catboost data models
otherColumns = {
    'eventid': 'object',
    'time': 'datetime',
    'problem': 'object',
    'triggerid': 'object',
    'resolutionTime': 'datetime'
}